package vn.appsmobi.loader;

import org.json.JSONObject;

import vn.appsmobi.model.AppInfo;
import vn.appsmobi.ulti.Constant;
import vn.appsmobi.ulti.Log;
import vn.appsmobi.ulti.Request;
import android.content.Context;

public class AppDetailLoader extends BaseLoader
{
	private String appid;
	private String packagename;
    public AppDetailLoader(Context paramContext)
    {
        super(paramContext);
    }
      
    protected BaseResult getResultInstance()
    {
        return new Result();
    }
    
    protected BaseLoader.UpdateTask getUpdateTask()
    {
        return new AppDetailUpdateTask();
    	
    }
    
    public void setAppDetailID(String AppDetailid)
    {
    	this.appid = AppDetailid;
    }
    public void setAppPackageName(String AppPackageName)
    {
    	this.appid = AppPackageName;
    }
    protected BaseResult parseResult(JSONObject json, BaseResult result)
    throws Exception
    {      
        Result localResult = (Result)result; 
        localResult.mAppDetailInfos = (AppInfo) AppInfo.valueOf(json);
        return localResult;
    }
    
    private class AppDetailUpdateTask extends BaseLoader.UpdateTask
    {
        private AppDetailUpdateTask()
        {
            super();
        }

		@Override
		protected Request getRequest() {			
			Log.v(String.format(Constant.GET_APP_DETAIL_URL,AppDetailLoader.this.appid));
			return new Request(String.format(Constant.GET_APP_DETAIL_URL,AppDetailLoader.this.appid));
		}
             
    }
    
    public static final class Result extends BaseResult
    {
        public AppInfo mAppDetailInfos;
        
        protected int getCount()
        {
        	if(this.mAppDetailInfos != null)
        		return 1;
        	return 0;
        }
        
        public BaseResult shallowClone()
        {
            Result localResult = new Result();
            localResult.mAppDetailInfos = this.mAppDetailInfos;
            return localResult;
        }
    }

	
}